package test2;

public class PhoneTest {
    public static void main(String[] args){
        //创建数组
        Phone[] arr =new Phone[3];
        //创建手机对象
        Phone p1=new Phone("华为","月光白",5999,"活力版");
        Phone p2=new Phone("小米","银光紫",6999,"回馈版");
        Phone p3=new Phone("oppo","帝王绿",4999,"老友版");

        //把手机对象放入数组中
        arr[0]=p1;
        arr[1]=p2;
        arr[2]=p3;
        //遍历数组求出手机总价
        int sum =0;
        for (int i = 0; i < arr.length; i++) {
            //int sum=0;
            Phone phone=arr[i];
            sum+= phone.getPrice();
        }
        int average;
        average=sum/arr.length;
        System.out.println(average);
        }
    }

